# 
#     scene : define the simulation scene
#     

from CarraraObject import CarraraObject
from Camera import Camera
from boid import Boid
from mindset import CameraFocusMindset
from timer import Timer
from CarraraScene import CarraraScene

class Scene(CarraraScene):
  def __init__(self):
    CarraraScene.__init__(self)

    self.time = 0.0
    self.fps = 25.0
    self.camera = None
    self.camera_focus = None      
    self.timer = Timer(fps=self.fps,callback=(self,self.step))
    self.boids = []
    self.container = None
    
    
#
#  add a camera to the scene
#   to do : adjust max speed and max acceleration for both focus and camera for smooth travelling
#                     
  def add_camera(self,name,focus_name,offset=None):
    self.camera_focus = Boid(name=focus_name,mindset=CameraFocusMindset(scene=self),max_speed=9999,max_acceleration=9999,scene=self)
    self.camera = Camera(name=name,target=self.camera_focus,scene=self)
    if offset is not None:
      self.camera.offset = offset
      
  def add_boid(self,boid):
    self.boids.append(boid)
    boid.scene = self
    return boid
    
  def step(self,time):
    CarraraScene.step(self,time)
    print "stepping",time
    for b in self.boids:
      b.prepare_move()
    if self.camera_focus is not None:
       self.camera_focus.prepare_move()
    if self.camera is not None:
       self.camera.prepare_move ()
    for b in self.boids:
      b.move()
    if self.camera_focus is not None:
       self.camera_focus.move()
    if self.camera is not None:
       self.camera.move ()
    
    
    